package com.aloda.orangebank.controller;

import com.aloda.orangebank.anno.Log;
import com.aloda.orangebank.pojo.CardApplication;
import com.aloda.orangebank.pojo.Result;
import com.aloda.orangebank.service.CardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/card")
public class CardController {

    @Autowired
    private CardService cardService;

    @PostMapping("/log")
    public Result cardLog(@RequestBody CardApplication cardApplication){
        log.info("提交的申请：{}",cardApplication);
        int flag=cardService.cardLog(cardApplication);
        if(flag==1){
            return Result.success("提交成功");
        }else if(flag==2){
            return Result.error("您的申请过多，请耐心等待！");
        }
        return Result.error("提交失败,您的银行卡到达最大数量！");
    }
}
